<template>
  <div :class="{ cardWrap: true, rightSide: showRightSide }" @click="toDetail">
    <div class="bookBox">
      <img class="bookImg" :src="albumImg" alt="" />
      <div class="mask">
        <van-icon name="play-circle-o" />
        {{ albumPlayCount }}
      </div>
    </div>
    <div class="bookText">
      {{ albumTitle }}
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent } from 'vue';

export default defineComponent({
  name: 'scz-card',
});
</script>

<script setup lang="ts">
import { useRouter } from 'vue-router';

import { useFormatPlayCount } from '@/mixin/playCount.ts';
import { useFormatImgPath } from '@/mixin/formatImgPath';
const props = defineProps(['albumItem']);

const router = useRouter();
//生成新的id
const albumId = props.albumItem.albumId || props.albumItem.id;
// 确认是否产生右边距
const showRightSide = props.albumItem.id;
// 生成图片的新的路径

const imgPath =
  props.albumItem.coverPath ||
  props.albumItem.albumInfo?.cover ||
  props.albumItem.albumCoverPath;
const albumImg = useFormatImgPath(imgPath);


// 生成新的标题
const albumTitle =
  props.albumItem.albumTitle ||
  props.albumItem.title ||
  props.albumItem.albumInfo.title;

// 生成新的播放数据
const playCount =
  props.albumItem.albumPlayCount ||
  props.albumItem.playCount ||
  props.albumItem.statCountInfo.playCount;
const albumPlayCount = useFormatPlayCount(playCount);

// 跳转到详情页面
function toDetail() {
  router.push('/detail/' + albumId);
}
</script>

<style scoped lang="less">
.rightSide {
  margin-right: 10px;
}
.cardWrap {
  // margin-right: 10px;
  padding: 1px 0;
  width: 103px;
  flex-grow: 0;
  flex-shrink: 0;
  .bookBox {
    position: relative;
    font-size: 12px;
    border-radius: 10px;
    overflow: hidden;
    .bookImg {
      vertical-align: middle;
      width: 100%;
      height: 103px;
    }
    .mask {
      width: 100%;
      height: 28px;
      position: absolute;
      padding-left: 5px;
      bottom: 0;
      line-height: 28px;
      //   background-color: rgba(251, 251, 251, 0.326);
      background-image: linear-gradient(
        180deg,
        rgba(3, 3, 3, 0) 9%,
        rgba(0, 0, 0, 0.58) 100%
      );
      color: #fff;
    }
  }
  .bookText {
    height: 36px;
    font-size: 13px;
    margin: 6px 0 11px;
    color: #333;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    text-overflow: ellipsis;
  }
}
</style>
